﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TSharp.Core.Util;
using System.Diagnostics;
using TSharp.Core.Net;
[assembly: TSharp.Core.Osgi.RegTypeInit(typeof(Test))]

namespace TSharp.Core.Net
{

    /// <summary>
    /// 
    /// </summary>
    public class Node
    {
        /// <summary>
        /// Gets or sets the URL.
        /// </summary>
        /// <value>
        /// The URL.
        /// </value>
        public ParameterizedUri Url { get; set; }
        /// <summary>
        /// Gets or sets the method.
        /// </summary>
        /// <value>
        /// The method.
        /// </value>
        public HttpMethod Method { get; set; }
        /// <summary>
        /// Submits the data use the specifed session.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <returns></returns>
        public virtual byte[] SubmitData(HttpWebClient session)
        {
            if (Method == HttpMethod.Post)
            {
                return session.UploadValues(this.Url.AsUri, null, this.Url.Queries);
            }
            else
            {
                return session.DownloadData(this.Url.ToString());
            }
        }
        /// <summary>
        /// Submit use the specified session.
        /// </summary>
        /// <param name="session">The session.</param>
        /// <returns></returns>
        public virtual string Submit(HttpWebClient session)
        {
            var bytes = SubmitData(session);
            return session.Encoding.GetString(bytes);
        }

    }
    class IEFake
    {
        HttpWebClient client = new HttpWebClient();
        private LinkedList<Node> list = new LinkedList<Node>();
        public Node Submit(Node data)
        {
            client.QueryString = data.Url.Queries;
            client.DownloadData("");
            var s = client.DownloadString(data.Url.ToString());
            return data;
        }
    }

    class Test
    {
        static Test()
        {
            try
            {
                string test = "http://www.kldjy.com/?fromuid=1306483";
                HttpWebClient client = new HttpWebClient();
                client.DownloadStringCompleted += new System.Net.DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
                client.DownloadStringAsync(new Uri(test), null);

            }
            catch (Exception)
            {

            }
        }

        static void client_DownloadStringCompleted(object sender, System.Net.DownloadStringCompletedEventArgs e)
        {
            
        }


    }
}
